<template>
  <el-card shadow="never">
    <template #header>
      <!-- 标题 -->
      <div class="flex flex-row items-center justify-between">
        <CardTitle title="博主排行" />
        <!-- 查询条件 -->
        <ShortcutDateRangePicker ref="shortcutDateRangePicker" @change="handleDateRangeChange" />
      </div>
    </template>
    <!-- 排行列表 -->
    <el-table v-loading="loading" :data="list" @sort-change="handleSortChange">
      <el-table-column label="博主信息" align="center" prop="userInfo" min-width="100">
        <template #default="{ row }">
          <el-image
            :src="row.user?.avatar"
            :preview-src-list="[row.user?.avatar]"
            class="h-30px w-30px"
            preview-teleported
          />
          <br />
          <el-text>{{ row.user?.nickname }}</el-text>
        </template>
      </el-table-column>
      <el-table-column label="粉丝数" prop="fansCount" min-width="50" sortable="custom" />
      <el-table-column label="关注数" prop="followCount" min-width="50" sortable="custom" />
      <el-table-column label="视频数" prop="vlogCount" min-width="50" sortable="custom" />
      <el-table-column label="点赞数" prop="sendLikeCount" min-width="50" sortable="custom" />
      <el-table-column label="得赞数" prop="receiveLikeCount" min-width="50" sortable="custom" />
      <el-table-column label="收藏数" prop="sendFavoriteCount" min-width="50" sortable="custom" />
      <el-table-column
        label="得藏数"
        prop="receiveFavoriteCount"
        min-width="50"
        sortable="custom"
      />
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getVLogInfoList"
    />
  </el-card>
</template>
<script lang="ts" setup>
import { VLogStatisticsApi, VLogStatisticsVO } from '@/api/vlog/statistics'
import { CardTitle } from '@/components/Card'
import { buildSortingField } from '@/utils'

/** 视频排行 */
defineOptions({ name: 'VLogRank' })

const handleSortChange = (params: any) => {
  queryParams.sortingFields = [buildSortingField(params)]
  getVLogInfoList()
}

const handleDateRangeChange = (times: any[]) => {
  queryParams.times = times as []
  getVLogInfoList()
}

const shortcutDateRangePicker = ref()
// 查询参数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  times: [],
  sortingFields: {}
})
const loading = ref(false) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref<VLogStatisticsVO[]>([]) // 列表的数据

/** 查询视频列表 */
const getVLogInfoList = async () => {
  loading.value = true
  try {
    const data = await VLogStatisticsApi.getVLogStatisticsRankPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 初始化 **/
onMounted(async () => {
  await getVLogInfoList()
})
</script>
<style lang="scss" scoped></style>
